/**
 * 
 */
package runner;

import java.io.IOException;
import java.util.Map.Entry;

import present.Constant;
import present.Present;
import property.UserProperty;
import candy.BuilderChocoCandy;
import candy.BuilderCookies;
import candy.BuilderMilkCandy;
import candy.ChocoType;
import candy.Sweet;

/**
 * @author 
 *
 */
public class Runner {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {		
		

		String s1= "src\\candy1.properties";
		String s2= "src\\candy2.properties";
		String s3= "src\\candy3.properties";
		
		int id = 0;
		String name = "";
		double albumens = 0;
		double carbohydrate = 0;
		double fats = 0;
		double weight = 0;
		double price = 0;
		double rateOfMilk = 0;
		double rateOfFluor = 0;
		ChocoType chocoType = null;
		
		double maxPrice = Constant.maxPrice;
		double minCarbohydrates = Constant.minCarbohydrates;
		double maxCarbohydrates = Constant.maxCarbohydrates;
		
		Present present = new Present(maxPrice);
		
		UserProperty userProperty = new UserProperty();
		userProperty.propertyRead(s1);
		
		for ( Entry<String, String> entry : userProperty.getProperties().entrySet()){	
			if (entry.getKey().equals("id"))
				id = Integer.parseInt( entry.getValue());
			if (entry.getKey().equals("name"))
				name =  entry.getValue();
			if (entry.getKey().equals("albumens"))
				albumens = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("carbohydrate"))
				carbohydrate = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("fats"))
				fats = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("weight"))
				weight = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("price"))
				price = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("rateOfMilk"))
				rateOfMilk = Double.parseDouble( entry.getValue());
				}
		
		BuilderMilkCandy builderMilkCandy = new BuilderMilkCandy (id, name, albumens, 
				 fats, carbohydrate, weight, price, rateOfMilk);	
		
		if (present.addSweet(builderMilkCandy.getSweet())) 
			System.out.println("Sweet is adding");
			else System.out.println("Sweet isn't adding");
	// adding second sweet	
		userProperty.propertyRead(s2);
		for ( Entry<String, String> entry : userProperty.getProperties().entrySet()){	
			if (entry.getKey().equals("id"))
				id = Integer.parseInt( entry.getValue());
			if (entry.getKey().equals("name"))
				name =  entry.getValue();
			if (entry.getKey().equals("albumens"))
				albumens = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("carbohydrate"))
				carbohydrate = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("fats"))
				fats = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("weight"))
				weight = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("price"))
				price = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("rateOfMilk"))
				albumens = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("chocoType"))
				chocoType = ChocoType.valueOf( entry.getValue());
				}
		
		BuilderChocoCandy builderChocoCandy = new BuilderChocoCandy (id, name, albumens, 
				 fats, carbohydrate, weight, price, rateOfMilk, chocoType);	
	
		if (present.addSweet(builderChocoCandy.getSweet())) 
			System.out.println("Sweet is adding");
			else System.out.println("Sweet isn't adding");
		
		//adding third sweet
		userProperty.propertyRead(s3);
		
		for ( Entry<String, String> entry : userProperty.getProperties().entrySet()){	
			if (entry.getKey().equals("id"))
				id = Integer.parseInt( entry.getValue());
			if (entry.getKey().equals("name"))
				name =  entry.getValue();
			if (entry.getKey().equals("albumens"))
				albumens = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("carbohydrate"))
				carbohydrate = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("fats"))
				fats = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("weight"))
				weight = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("price"))
				price = Double.parseDouble( entry.getValue());
			if (entry.getKey().equals("rateOfFluor"))
				rateOfFluor = Double.parseDouble( entry.getValue());
				}
		
		BuilderCookies builderCookies = new BuilderCookies (id, name, albumens, 
				 fats, carbohydrate, weight, price, rateOfFluor);	
		
		if (present.addSweet(builderCookies.getSweet())) 
			System.out.println("Sweet is adding");
			else System.out.println("Sweet isn't adding");
		
		System.out.println( "Initial present");
		System.out.println( present.toString());
		
		present.sortByPrice();		
		System.out.println( "Sorted present");
		System.out.println( present.toString());
		
		for (Sweet sweet : present.getRangeCarbohydrates(minCarbohydrates,
											maxCarbohydrates)){	
			System.out.println(sweet.getName() + sweet.getCarbohydrates() + "\n");			
				}
		 		

	}

}
